package com.lm.easy.service;

import com.lm.easy.rule.AgeRule;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.DefaultRulesEngine;
import org.springframework.stereotype.Service;

@Service
public class RuleService {

    public void executeRules(int age) {
        // 创建 Facts
        Facts facts = new Facts();
        facts.put("age", age);

        // 注册规则
        Rules rules = new Rules();
        rules.register(new AgeRule());

        // 创建引擎
        RulesEngine rulesEngine = new DefaultRulesEngine();
        rulesEngine.fire(rules, facts);
    }
}